package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.mapper.AfterMapper;
import com.woniuxy.pojo.After;
import com.woniuxy.pojo.dto.AfterDTO;
import com.woniuxy.service.AfterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 29331
* @description 针对表【t_after(售后申请表)】的数据库操作Service实现
* @createDate 2025-06-05 16:51:25
*/
@Service
public class AfterServiceImpl extends ServiceImpl<AfterMapper, After>
    implements AfterService {

    @Autowired
    AfterMapper afterMapper;

    @Override
    public Page<After> getAllService(Integer pageSize, Integer pageNum, Integer service) {
        Page<After> page = new Page<>(pageNum,pageSize,true);
        LambdaQueryWrapper<After> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(After::getService,service);


        return afterMapper.selectPage(page,wrapper);
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        LambdaUpdateWrapper<After> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(After::getId,ids)
                .set(After::getDeleted,1);
        afterMapper.update(null,wrapper);
    }

    @Override
    public List<After> selectByNumAndStatus(AfterDTO afterDTO, Integer service) {
        LambdaQueryWrapper<After> wrapper = new LambdaQueryWrapper<>();

        if (afterDTO.getServiceNum() != null && !afterDTO.getServiceNum().isEmpty()){
            wrapper.like(After::getServiceNum,afterDTO.getServiceNum());
        }

        if (afterDTO.getStatus() != null){
            wrapper.eq(After::getStatus,afterDTO.getStatus());
        }

        if (afterDTO.getStartDate() != null && afterDTO.getEndDate() != null){
            wrapper.between(After::getCreateTime,afterDTO.getStartDate(),afterDTO.getEndDate());

        }

        wrapper.eq(After::getService,service);
        return afterMapper.selectList(wrapper);
    }

    @Override
    public List<After> getOrderByIds(List<Long> ids) {
        return afterMapper.selectBatchIds(ids);
    }
}




